package handlers

import (
	"github.com/gin-gonic/gin"
	"screen-master/model"
	"screen-master/pkg"
)

func Login(c *gin.Context) {
	tel := c.PostForm("tel")
	password := c.PostForm("password")
	data := model.User{
		Tel:      tel,
		Password: pkg.Str(password),
	}

	err := model.DB.Find(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "登录失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "登录成功",
	})
	return
}

func List(c *gin.Context) {
	var screen model.Screen
	model.DB.Find(&screen)
	c.JSON(200, gin.H{
		"code": 400,
		"msg":  "查询成功",
		"data": screen,
	})
	return
}
